package com.leadiv.cards.Rook;

import com.leadiv.cards.Card;
import com.leadiv.cards.Deck;
import java.util.Vector;

/**
 * RookCard class
 * @author pborrego
 * This represnts a rook card in the game Rook. A card can have the suits:
 * Black, Green, Red or Yellow. Each suit has 1-14 face cards though depending
 * on the amount of players some face cards are not used. The Rook card has a
 * suit of Trump and face value of Rook. 5's have a value of 5 points, 10's
 * and 14's have a value of 10 points each and Rook has a value of 20 points.
 */
public class RookCard extends Card implements Comparable<Card> {
    public RookCard(String suit, String face, double value) {
        super(suit, face, value);
    }

    public RookCard(RookCard c) {
        super(c);
    }

    /**
     * cardFactory
     * @author pborrego
     * @param suits
     * @param faces
     * @param values
     * @return a set of cards based on the suits, faces and values given.
     */
    public static Deck<RookCard> cardFactory(String[] suits, String[] faces, Double[] values)
    {
        Vector<RookCard> cards = new Vector<RookCard>();
        int i = 0;
        int j = 0;

        for(; i < suits.length; i++)
            for(j = 0; j < faces.length; j++)
                cards.add(new RookCard(suits[i], faces[j], values[j]));

        return new Deck<RookCard>(cards);
    }

    /**
     * compareTo
     * @param o - Card to compare to
     * @return  0 for equal. -1 if the current card (this) has a greater value
     * or suit. 1 if the current card (this) has a lesser value or suit.
     */
    @Override
    public int compareTo(Card o) {
        int fv1, fv2;
        String s1, s2;
        RookCard c = (RookCard) o;

        if(this.getSuit().equals(c.getSuit())) {
            fv1 = (int) (this.getFace().equals("Rook") ?
                this.getValue() : Integer.parseInt(this.getFace())) ;
            fv2 = (int) (c.getFace().equals("Rook") ?
                c.getValue() : Integer.parseInt(c.getFace())) ;

            if(fv1 > fv2) return -1;
            if(fv1 < fv2) return 1;
            return 0;
        }

        s1 = this.getSuit().equals("Trump") ? "Z" + this.getSuit() : this.getSuit();
        s2 = c.getSuit().equals("Trump") ? "Z" + c.getSuit() : c.getSuit();

        return s1.compareTo(s2);
    }
}
